/* pfs0DPlayerPositionAndLook.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <packet/pfs0DPlayerPositionAndLook.h>
#include <wrapper/JavaStreamWrapper.h>

pfs0DPlayerPositionAndLook::pfs0DPlayerPositionAndLook()
    : McPacketFromServer(0x0D), x(.0), stance(.0), y(.0), z(.0), yaw(.0), pitch(.0), onGround(false)
{
}

unsigned int pfs0DPlayerPositionAndLook::length()
{
    return 1 + 8 + 8 + 8 + 8 + 4 + 4 + 1;
}

int16_t pfs0DPlayerPositionAndLook::setField(uint8_t field, void* value)
{

    switch (field)
    {
        case 0:
        default: return 8;
        case 1: x = JavaStreamWrapper::readDouble(value); return 8;
        case 2: stance = JavaStreamWrapper::readDouble(value); return 8;
        case 3: y = JavaStreamWrapper::readDouble(value); return 8;
        case 4: z = JavaStreamWrapper::readDouble(value); return 4;
        case 5: yaw = JavaStreamWrapper::readFloat(value); return 4;
        case 6: pitch = JavaStreamWrapper::readFloat(value); return 1;
        case 7: onGround = JavaStreamWrapper::readBoolean(value); return -1;
    }
}

double pfs0DPlayerPositionAndLook::getX()
{
    return x;
}

double pfs0DPlayerPositionAndLook::getStance()
{
    return stance;
}

double pfs0DPlayerPositionAndLook::getY()
{
    return y;
}

double pfs0DPlayerPositionAndLook::getZ()
{
    return z;
}

float pfs0DPlayerPositionAndLook::getYaw()
{
    return yaw;
}

float pfs0DPlayerPositionAndLook::getPitch()
{
    return pitch;
}

bool pfs0DPlayerPositionAndLook::getOnGround()
{
    return onGround;
}


